<script setup>
import { onMounted, ref } from 'vue'
import { Edit, Delete } from '@element-plus/icons-vue'
import { getArticleChannelService, ArticleDelChannelService } from '@/api/article.js'
import channelDialog from './components/channelDialog.vue'
const channelList = ref([])
const loading = ref(false)
const dialog = ref()

const getChannelList = async () => {
  loading.value = true
  const res = await getArticleChannelService()
  channelList.value = res.data.data
  loading.value = false
}
onMounted(() => {
  getChannelList()
})
const addChannel = () => {
  dialog.value.openEditWay({})
  getChannelList()
}
const editChannel = (row) => {
  dialog.value.openEditWay(row)
  getChannelList()
}
const delChannel = async (row) => {
  await ArticleDelChannelService(row.id)
  getChannelList()
}
// const tableData = [
//   {
//     date: '2016-05-03',
//     name: 'Tom',
//     address: 'No. 189, Grove St, Los Angeles',
//   },
//   {
//     date: '2016-05-02',
//     name: 'Tom',
//     address: 'No. 189, Grove St, Los Angeles',
//   },
//   {
//     date: '2016-05-04',
//     name: 'Tom',
//     address: 'No. 189, Grove St, Los Angeles',
//   },
//   {
//     date: '2016-05-01',
//     name: 'Tom',
//     address: 'No. 189, Grove St, Los Angeles',
//   },
// ]
</script>
<template>
  <PageContent title="文章分类">
    <template #extra>
      <el-button @click="addChannel">添加分类</el-button>
    </template>

    <el-table v-loading="loading" :data="channelList" style="width: 100%">
      <el-table-column type="index" label="序号" width="100" />
      <el-table-column prop="cate_name" label="分类名称" />
      <el-table-column prop="cate_alias" label="分类别名" />
      <el-table-column prop="address" label="操作" width="180">
        <template #default="scoped">
          <el-button :icon="Edit" @click="editChannel(scoped.row, scoped.$index)"></el-button>
          <el-button
            :icon="Delete"
            type="danger"
            @click="delChannel(scoped.row, scoped.$index)"
          ></el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>

    <channelDialog ref="dialog"></channelDialog>
  </PageContent>
</template>

<style scoped></style>
